package com.excel.validators.log;

import java.io.PrintStream;

/**
 * @author wangxiaoliang10
 *
 * 2017年8月30日
 */
public final class Log {

		private String simpleName;
	
		private final PrintStream logger = System.out;
		
		private final PrintStream error = System.err;
	
		private static final String INFO = "[INFO]: ";
		
		private static final String ERROR = "[ERROR]: ";
		
		private static final String WARN = "[WARNING]: ";
		
		public Log(String simpleName) {
				this.simpleName = simpleName;
		}

		public void info(String message) {
				logger.println(INFO + message);
		}

		public boolean isTraceEnabled() {
				return LogFactory.traceEnabled;
		}

		public void trace(String message) {
				logger.println(INFO + message);
		}

		public void error(String message, Exception e) {
				if (e != null) {
						logger.println(e.getClass().getCanonicalName());
						printStack(e.getStackTrace()[0]);
				}
				logger.println(ERROR + message);
		}

		public void printStack(StackTraceElement ste) {
				error.print("at ");
				error.print(ste.getClassName());
				error.print(".");
				error.print(ste.getMethodName());
				error.print("(");
				error.print(ste.getFileName());
				error.print(":");
				error.print(ste.getLineNumber());
				error.print(")");
		}
		
		public void warn(String message) {
				logger.println(WARN + message);
		}
}
